package app.page;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import org.openqa.selenium.By;

import java.util.Map;

public class ContactPage extends BasePage{

    By menuAction=By.xpath("(//android.widget.TextView)[3]");
    By search=By.xpath("(//android.widget.TextView)[2]");
    By content=By.xpath("//android.widget.EditText");
    By result=By.xpath("(//android.widget.TextView)[3]");
    // 个人信息页面管理菜单
    By personMenu=By.xpath("(//android.widget.TextView)[3]");
    By editPerson=By.cssSelector("*[text='编辑成员']");
    By deletePerson=By.cssSelector("*[text='删除成员']");
    By ok=By.cssSelector("*[text='确定']");
    By back=By.xpath("(//android.widget.TextView)[1]");

    // 部门管理菜单
    By deptMenu=By.xpath("(//android.widget.TextView)[3]");
    // 更多管理
    By moreManager=By.cssSelector("*[text='更多管理']");
    By deleteDept=By.cssSelector("*[text='删除部门']");
    By close=By.xpath("(//android.widget.TextView)[3]");

    public ContactPage(AppiumDriver<MobileElement> driver) {
        super(driver);
    }

    public PersonPage toPersonPage(){
        click(menuAction);
        return new PersonPage(driver);
    }

    public ContactPage searchPage(String content) throws InterruptedException {
        click(search);
        sendKeys(this.content,content);
        waitSecond();
        return this;
    }

    public void searchPerson(String content) throws InterruptedException {
        click(search);
        sendKeys(this.content,content);
        waitSecond();
    }

    public String getName(){

        return getText(result);

    }

    public void deletePerson(String id) throws InterruptedException {
        searchPerson(id);
        click(result);
        click(personMenu);
        click(editPerson);
        click(deletePerson);
        click(ok);
        click(back);
    }

    public void deleteDept(String deptName) throws InterruptedException {
        click(By.cssSelector("*[text='"+deptName+"']"));
        click(deptMenu);
        click(moreManager);
        click(deleteDept);
        click(ok);
        click(close);
        click(back);
    }

}
